﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EasyTrader.Option
{
    using CodeList = List<EasyTrader.DataSet.CodeTable>;
    using DDECollectionList = List<EasyTrader.Option.DDEData>;
    using SimpleDataList = List<EasyTrader.DataSet.SimpleData>;

    public partial class OpUpDownTargetTable : System.Windows.Forms.Form
    {
        public OpUpDownTargetTable()
        {
            InitializeComponent();
        }



        #region Internal Class
        public class CellDoubleClickEvent : SourceGrid.Cells.Controllers.ControllerBase
        {
            private EasyTrader.Option.OpUpDownTargetTable m_DDEFrm = null;
            public EasyTrader.Option.OpUpDownTargetTable DDEFrm
            {
                get { return m_DDEFrm; }
                set { m_DDEFrm = value; }
            }


            private SourceGrid.Grid m_GridDDE = null;
            public SourceGrid.Grid GridDDE
            {
                get { return m_GridDDE; }
                set { m_GridDDE = value; }
            }

            public override void OnDoubleClick(SourceGrid.CellContext sender, EventArgs e)
            {
                base.OnDoubleClick(sender, e);
                SourceGrid.Cells.Cell curCell = (SourceGrid.Cells.Cell)sender.Cell;
                //MessageBox.Show(sender.Grid, curCell.Column.Index.ToString() + curCell.Row.Index.ToString());
                //if (m_DDEFrm.TargetValueFilled == true)
                //{
                //EasyTrader.Chart.CallPutChart callPutChart = new EasyTrader.Chart.CallPutChart(m_DDEFrm.OpDataSet);
                //callPutChart.Show();
                //}
                SourceGrid.Grid gridPrice = (SourceGrid.Grid)sender.Grid;
                //string closeVal = gridPrice[m_OrderFrm.centerRow, 3].Value.ToString();
                //if (closeVal == "")
                //    return;


            }
        }
        #endregion

        #region Member Functions

        private EasyTrader.Signal.TotalSignalManager m_EasyTraderSignalManager = null;
        public EasyTrader.Signal.TotalSignalManager EasyTraderSignalManager
        {
            get { return m_EasyTraderSignalManager; }
            set { m_EasyTraderSignalManager = value; }
        }


        private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private void InitTimer()
        {
            timer.Interval = 1000;
            timer.Tick += new EventHandler(OnTimerTick);
            timer.Start();
        }

        // 여기서 차트를 갱신해 준다.
        private void OnTimerTick(object sender, EventArgs e)
        {
            if (m_OpDataSet.DownLoader.AllOptChartDataDownloaded == false ||
                m_OpDataSet.DownLoader.ATMChanged == false)
                return;

            EasyTrader.Manager.OptPriceSysManager opManager = (EasyTrader.Manager.OptPriceSysManager)m_EasyTraderSignalManager.SysManagerList[GlobalVar.SysTypeOptPrice];

            List<EasyTrader.Option.CompVal> valList = opManager.CallStateWatcher.SigUpList;
            FillCallBreakUpList(valList);
            valList = opManager.CallStateWatcher.SigDownList;
            FillCallBreakDownList(valList);
            valList = opManager.PutStateWatcher.SigUpList;
            FillPutBreakUpList(valList);
            valList = opManager.PutStateWatcher.SigDownList;
            FillPutBreakDownList(valList);
        }
        #endregion

        #region Member Variables

        private int m_CellWidth = 50;
        private EasyTrader.ETDataSet m_OpDataSet = null;


        private SourceGrid.Cells.Views.Cell categoryView = null;
        private SourceGrid.Cells.Views.Cell headerView = null;
        private SourceGrid.Cells.Views.Cell priceView = null;
        private SourceGrid.Cells.Views.Cell buyView = null;
        private SourceGrid.Cells.Views.Cell sellView = null;
        private SourceGrid.Cells.Views.Cell centerView = null;
        private SourceGrid.Cells.Views.Cell normalView = null;

        private SourceGrid.Cells.Views.Cell highView = null;
        private SourceGrid.Cells.Views.Cell lowView = null;
        private SourceGrid.Cells.Views.Cell baseView = null;
        private SourceGrid.Cells.Views.Cell curView = null;

        private SourceGrid.Cells.Views.Cell upView = null;
        private SourceGrid.Cells.Views.Cell downView = null;
        #endregion

        #region  Grid Init

        public OpUpDownTargetTable(EasyTrader.ETDataSet opDataSet)
        {
            m_OpDataSet = opDataSet;
            InitializeComponent();
            InitGridCellView();
            InitGrid();
            InitTimer();
        }

        private void InitGrid()
        {
            if (m_OpDataSet == null)
                return;

            CellDoubleClickEvent doubleClickController = new CellDoubleClickEvent();
            doubleClickController.GridDDE = gridCall;
            doubleClickController.DDEFrm = this;


            gridCall.Redim(40, 14);
            gridCall.FixedRows = 3;
            gridCall.Rows[0].Height = 30;

            gridCall[0, 0] = new SourceGrid.Cells.Cell("콜옵션");
            gridCall[0, 0].SetSpan(1, 14);
            gridCall[0, 0].View = buyView;
            gridCall[1, 0] = new SourceGrid.Cells.Cell("돌파가격");
            gridCall[1, 0].SetSpan(1, 7);
            gridCall[1, 0].View = headerView;
            gridCall[1, 0].Column.Width = m_CellWidth;
            gridCall[1, 7] = new SourceGrid.Cells.Cell("붕괴가격");
            gridCall[1, 7].SetSpan(1, 7);
            gridCall[1, 7].View = headerView;
            gridCall[1, 7].Column.Width = m_CellWidth;

            gridCall[2, 0] = new SourceGrid.Cells.Cell("행사가");
            gridCall[2, 0].View = buyView;
            gridCall[2, 0].Column.Width = m_CellWidth;
            gridCall[2, 1] = new SourceGrid.Cells.Cell("종류");
            gridCall[2, 1].View = buyView;
            gridCall[2, 1].Column.Width = m_CellWidth;
            gridCall[2, 2] = new SourceGrid.Cells.Cell("가격");
            gridCall[2, 2].View = buyView;
            gridCall[2, 2].Column.Width = m_CellWidth;
            gridCall[2, 3] = new SourceGrid.Cells.Cell("현재가");
            gridCall[2, 3].View = buyView;
            gridCall[2, 3].Column.Width = m_CellWidth;
            gridCall[2, 4] = new SourceGrid.Cells.Cell("차이");
            gridCall[2, 4].View = buyView;
            gridCall[2, 4].Column.Width = m_CellWidth;
            gridCall[2, 5] = new SourceGrid.Cells.Cell("첫시간");
            gridCall[2, 5].View = buyView;
            gridCall[2, 5].Column.Width = m_CellWidth;
            gridCall[2, 6] = new SourceGrid.Cells.Cell("최근시간");
            gridCall[2, 6].View = buyView;
            gridCall[2, 6].Column.Width = m_CellWidth;


            gridCall[2, 7] = new SourceGrid.Cells.Cell("행사가");
            gridCall[2, 7].View = sellView;
            gridCall[2, 7].Column.Width = m_CellWidth;
            gridCall[2, 8] = new SourceGrid.Cells.Cell("종류");
            gridCall[2, 8].View = sellView;
            gridCall[2, 8].Column.Width = m_CellWidth;
            gridCall[2, 9] = new SourceGrid.Cells.Cell("가격");
            gridCall[2, 9].View = sellView;
            gridCall[2, 9].Column.Width = m_CellWidth;
            gridCall[2, 10] = new SourceGrid.Cells.Cell("현재가");
            gridCall[2, 10].View = sellView;
            gridCall[2, 10].Column.Width = m_CellWidth;
            gridCall[2, 11] = new SourceGrid.Cells.Cell("차이");
            gridCall[2, 11].View = sellView;
            gridCall[2, 11].Column.Width = m_CellWidth;

            gridCall[2, 12] = new SourceGrid.Cells.Cell("첫시간");
            gridCall[2, 12].View = sellView;
            gridCall[2, 12].Column.Width = m_CellWidth;

            gridCall[2, 13] = new SourceGrid.Cells.Cell("최근시간");
            gridCall[2, 13].View = sellView;
            gridCall[2, 13].Column.Width = m_CellWidth;



            // 돌파 가격 채우기
            for (int i = 3; i < gridCall.RowsCount; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    gridCall[i, j] = new SourceGrid.Cells.Cell();
                    gridCall[i, j].View = highView;
                    gridCall[i, j].Column.Width = m_CellWidth;
                }
            }

            // 붕괴 가격 채우기
            for (int i = 3; i < gridCall.RowsCount; i++)
            {
                for (int j = 7; j < 14; j++)
                {
                    gridCall[i, j] = new SourceGrid.Cells.Cell();
                    gridCall[i, j].View = lowView;
                    gridCall[i, j].Column.Width = m_CellWidth;
                }
            }


            gridPut.Redim(40, 14);
            gridPut.FixedRows = 3;
            gridPut.Rows[0].Height = 30;

            gridPut[0, 0] = new SourceGrid.Cells.Cell("풋옵션");
            gridPut[0, 0].SetSpan(1, 14);
            gridPut[0, 0].View = sellView;
            gridPut[1, 0] = new SourceGrid.Cells.Cell("돌파가격");
            gridPut[1, 0].SetSpan(1, 7);
            gridPut[1, 0].View = headerView;
            gridPut[1, 0].Column.Width = m_CellWidth;
            gridPut[1, 7] = new SourceGrid.Cells.Cell("붕괴가격");
            gridPut[1, 7].SetSpan(1, 7);
            gridPut[1, 7].View = headerView;
            gridPut[1, 7].Column.Width = m_CellWidth;

            gridPut[2, 0] = new SourceGrid.Cells.Cell("행사가");
            gridPut[2, 0].View = buyView;
            gridPut[2, 0].Column.Width = m_CellWidth;
            gridPut[2, 1] = new SourceGrid.Cells.Cell("종류");
            gridPut[2, 1].View = buyView;
            gridPut[2, 1].Column.Width = m_CellWidth;
            gridPut[2, 2] = new SourceGrid.Cells.Cell("가격");
            gridPut[2, 2].View = buyView;
            gridPut[2, 2].Column.Width = m_CellWidth;
            gridPut[2, 3] = new SourceGrid.Cells.Cell("현재가");
            gridPut[2, 3].View = buyView;
            gridPut[2, 3].Column.Width = m_CellWidth;
            gridPut[2, 4] = new SourceGrid.Cells.Cell("차이");
            gridPut[2, 4].View = buyView;
            gridPut[2, 4].Column.Width = m_CellWidth;
            gridPut[2, 5] = new SourceGrid.Cells.Cell("첫시간");
            gridPut[2, 5].View = buyView;
            gridPut[2, 5].Column.Width = m_CellWidth;
            gridPut[2, 6] = new SourceGrid.Cells.Cell("최근시간");
            gridPut[2, 6].View = buyView;
            gridPut[2, 6].Column.Width = m_CellWidth;


            gridPut[2, 7] = new SourceGrid.Cells.Cell("행사가");
            gridPut[2, 7].View = sellView;
            gridPut[2, 7].Column.Width = m_CellWidth;
            gridPut[2, 8] = new SourceGrid.Cells.Cell("종류");
            gridPut[2, 8].View = sellView;
            gridPut[2, 8].Column.Width = m_CellWidth;
            gridPut[2, 9] = new SourceGrid.Cells.Cell("가격");
            gridPut[2, 9].View = sellView;
            gridPut[2, 9].Column.Width = m_CellWidth;
            gridPut[2, 10] = new SourceGrid.Cells.Cell("현재가");
            gridPut[2, 10].View = sellView;
            gridPut[2, 10].Column.Width = m_CellWidth;
            gridPut[2, 11] = new SourceGrid.Cells.Cell("차이");
            gridPut[2, 11].View = sellView;
            gridPut[2, 11].Column.Width = m_CellWidth;
            gridPut[2, 12] = new SourceGrid.Cells.Cell("첫시간");
            gridPut[2, 12].View = sellView;
            gridPut[2, 12].Column.Width = m_CellWidth;

            gridPut[2, 13] = new SourceGrid.Cells.Cell("최근시간");
            gridPut[2, 13].View = sellView;
            gridPut[2, 13].Column.Width = m_CellWidth;



            // 돌파 가격 채우기
            for (int i = 3; i < gridPut.RowsCount; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    gridPut[i, j] = new SourceGrid.Cells.Cell();
                    gridPut[i, j].View = highView;
                    gridPut[i, j].Column.Width = m_CellWidth;
                }
            }

            // 붕괴 가격 채우기
            for (int i = 3; i < gridPut.RowsCount; i++)
            {
                for (int j = 7; j < 14; j++)
                {
                    gridPut[i, j] = new SourceGrid.Cells.Cell();
                    gridPut[i, j].View = lowView;
                    gridPut[i, j].Column.Width = m_CellWidth;
                }
            }


        }


        public void InitGridCellView()
        {
            DevAge.Drawing.RectangleBorder border = new DevAge.Drawing.RectangleBorder(new DevAge.Drawing.BorderLine(Color.DarkGreen), new DevAge.Drawing.BorderLine(Color.DarkGreen));
            //Category header
            //DevAge.Drawing.BorderLine top = new DevAge.Drawing.BorderLine(Color.Blue, 2);
            //DevAge.Drawing.RectangleBorder rcBorder = new DevAge.Drawing.RectangleBorder();

            categoryView = new SourceGrid.Cells.Views.Cell();
            categoryView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.RoyalBlue, Color.LightBlue, 0);
            categoryView.ForeColor = Color.FromKnownColor(KnownColor.ActiveCaptionText);
            categoryView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            categoryView.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            categoryView.Font = new Font("굴림", 9, FontStyle.Bold);


            headerView = new SourceGrid.Cells.Views.Cell();
            headerView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.ForestGreen, Color.FloralWhite, 0);
            headerView.ForeColor = Color.FromKnownColor(KnownColor.ActiveCaptionText);
            headerView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            headerView.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            headerView.Font = new Font("굴림", 9, FontStyle.Bold);

            priceView = new SourceGrid.Cells.Views.Cell();
            priceView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.ForestGreen, Color.ForestGreen, 0);
            //priceView.ForeColor = Color.FromKnownColor(KnownColor.ActiveCaptionText);
            priceView.ForeColor = Color.White;
            priceView.BackColor = Color.LightSteelBlue;
            priceView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            priceView.Border = DevAge.Drawing.RectangleBorder.RectangleBlack1Width;
            priceView.Font = new Font("굴림", 9, FontStyle.Regular);

            buyView = new SourceGrid.Cells.Views.Cell();
            buyView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.Red, Color.White, 0);
            //priceView.ForeColor = Color.FromKnownColor(KnownColor.ActiveCaptionText);
            buyView.BackColor = Color.LightPink;
            buyView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            //priceView.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            buyView.Font = new Font("굴림", 9, FontStyle.Regular);

            sellView = new SourceGrid.Cells.Views.Cell();
            sellView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.Blue, Color.White, 0);
            //priceView.ForeColor = Color.FromKnownColor(KnownColor.ActiveCaptionText);
            sellView.BackColor = Color.LightSteelBlue;
            sellView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            //priceView.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            sellView.Font = new Font("굴림", 9, FontStyle.Regular);

            centerView = new SourceGrid.Cells.Views.Cell();
            centerView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.FloralWhite, Color.LightSteelBlue, 90);
            centerView.ForeColor = Color.Red;
            centerView.BackColor = Color.LightSteelBlue;
            centerView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            //priceView.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            centerView.Font = new Font("굴림", 9, FontStyle.Regular);

            normalView = new SourceGrid.Cells.Views.Cell();
            //normalView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.ForestGreen, Color.FloralWhite, 0);
            normalView.ForeColor = Color.Black;
            normalView.BackColor = Color.White;
            normalView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            normalView.Font = new Font("굴림", 9, FontStyle.Regular);


            highView = new SourceGrid.Cells.Views.Cell();
            highView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.LightPink, Color.White, 90);
            highView.ForeColor = Color.Black;
            highView.BackColor = Color.White;
            highView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            highView.Font = new Font("굴림", 9, FontStyle.Regular);

            lowView = new SourceGrid.Cells.Views.Cell();
            lowView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.LightBlue, Color.White, 90);
            lowView.ForeColor = Color.Black;
            lowView.BackColor = Color.White;
            lowView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            //lowView.Border. = DevAge.Drawing.BorderLine;
            lowView.Font = new Font("굴림", 9, FontStyle.Regular);


            baseView = new SourceGrid.Cells.Views.Cell();
            baseView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.LightGreen, Color.White, 90);
            baseView.ForeColor = Color.Red;
            baseView.BackColor = Color.White;
            baseView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            baseView.Font = new Font("굴림", 9, FontStyle.Bold);

            curView = new SourceGrid.Cells.Views.Cell();
            //curView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.White, Color.White, 90);
            curView.ForeColor = Color.Black;
            curView.BackColor = Color.White;
            curView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            curView.Font = new Font("굴림", 9, FontStyle.Regular);


            upView = new SourceGrid.Cells.Views.Cell();
            upView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.LightGreen, Color.White, 90);
            upView.ForeColor = Color.Red;
            upView.BackColor = Color.White;
            upView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            upView.Font = new Font("굴림", 9, FontStyle.Regular);

            downView = new SourceGrid.Cells.Views.Cell();
            downView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.LightGreen, Color.White, 90);
            downView.ForeColor = Color.Blue;
            downView.BackColor = Color.White;
            downView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            downView.Font = new Font("굴림", 9, FontStyle.Regular);

        }
        #endregion

        #region Fill Process

        private void FillCallBreakUpList(List<EasyTrader.Option.CompVal> a_List)
        {
            if (a_List.Count == 0)
                return;

            for (int i = 3; i < a_List.Count; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    gridCall[i + 3, j].Value = "";
                }
            }

            for (int i = 0; i < a_List.Count; i++)
            {
                EasyTrader.Option.CompVal curVal = a_List[i];
                string priceCode = curVal.BreakCode.Substring(curVal.BreakCode.Length - 3, 3);
                gridCall[i + 3, 0].Value = priceCode;
                string type = "없음";
                if (curVal.Type == 0)
                    type = "월저";
                else if (curVal.Type == 1)
                    type = "마디";
                else if (curVal.Type == 2)
                    type = "기준";
                else if (curVal.Type == 3)
                    type = "목표";
                else if (curVal.Type == 4)
                    type = "월고";
                gridCall[i + 3, 1].Value = type;
                gridCall[i + 3, 2].Value = curVal.Val;
                gridCall[i + 3, 3].Value = curVal.CurVal;
                gridCall[i + 3, 4].Value = (curVal.CurVal - curVal.Val).ToString("F2");
                gridCall[i + 3, 5].Value = curVal.FirstBreakUpTime;
                gridCall[i + 3, 6].Value = curVal.RecentBreakTime;
            }
        }

        private void FillCallBreakDownList(List<EasyTrader.Option.CompVal> a_List)
        {
            if (a_List.Count == 0)
                return;
            for (int i = 0; i < a_List.Count; i++)
            {
                EasyTrader.Option.CompVal curVal = a_List[i];
                string priceCode = curVal.BreakCode.Substring(curVal.BreakCode.Length - 3, 3);
                gridCall[i + 3, 7].Value = priceCode;
                string type = "없음";
                if (curVal.Type == 0)
                    type = "월저";
                else if (curVal.Type == 1)
                    type = "마디";
                else if (curVal.Type == 2)
                    type = "기준";
                else if (curVal.Type == 3)
                    type = "목표";
                else if (curVal.Type == 4)
                    type = "월고";
                gridCall[i + 3, 8].Value = type;
                gridCall[i + 3, 9].Value = curVal.Val;
                gridCall[i + 3, 10].Value = curVal.CurVal;
                gridCall[i + 3, 11].Value = (curVal.CurVal - curVal.Val).ToString("F2");
                gridCall[i + 3, 12].Value = curVal.FirstBreakDownTime;
                gridCall[i + 3, 13].Value = curVal.RecentBreakTime;
            }
        }

        private void FillPutBreakUpList(List<EasyTrader.Option.CompVal> a_List)
        {
            if (a_List.Count == 0)
                return;

            for (int i = 3; i < a_List.Count; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    gridPut[i + 3, j].Value = "";
                }
            }


            for (int i = 0; i < a_List.Count; i++)
            {
                EasyTrader.Option.CompVal curVal = a_List[i];
                string priceCode = curVal.BreakCode.Substring(curVal.BreakCode.Length - 3, 3);
                gridPut[i + 3, 0].Value = priceCode;
                string type = "없음";
                if (curVal.Type == 0)
                    type = "월저";
                else if (curVal.Type == 1)
                    type = "마디";
                else if (curVal.Type == 2)
                    type = "기준";
                else if (curVal.Type == 3)
                    type = "목표";
                else if (curVal.Type == 4)
                    type = "월고";
                gridPut[i + 3, 1].Value = type;
                gridPut[i + 3, 2].Value = curVal.Val;
                gridPut[i + 3, 3].Value = curVal.CurVal;
                gridPut[i + 3, 4].Value = (curVal.CurVal - curVal.Val).ToString("F2");
                gridPut[i + 3, 5].Value = curVal.FirstBreakUpTime;
                gridPut[i + 3, 6].Value = curVal.RecentBreakTime;
            }
        }

        private void FillPutBreakDownList(List<EasyTrader.Option.CompVal> a_List)
        {
            if (a_List.Count == 0)
                return;
            for (int i = 0; i < a_List.Count; i++)
            {
                EasyTrader.Option.CompVal curVal = a_List[i];
                string priceCode = curVal.BreakCode.Substring(curVal.BreakCode.Length - 3, 3);
                gridPut[i + 3, 7].Value = priceCode;
                string type = "없음";
                if (curVal.Type == 0)
                    type = "월저";
                else if (curVal.Type == 1)
                    type = "마디";
                else if (curVal.Type == 2)
                    type = "기준";
                else if (curVal.Type == 3)
                    type = "목표";
                else if (curVal.Type == 4)
                    type = "월고";
                gridPut[i + 3, 8].Value = type;
                gridPut[i + 3, 9].Value = curVal.Val;
                gridPut[i + 3, 10].Value = curVal.CurVal;
                gridPut[i + 3, 11].Value = (curVal.CurVal - curVal.Val).ToString("F2");
                gridPut[i + 3, 12].Value = curVal.FirstBreakDownTime;
                gridPut[i + 3, 13].Value = curVal.RecentBreakTime;
            }
        }

        private int FindCallBreakUpID(string a_PriceCode, double a_Val)
        {
            int rowID = -1;

            int rowCount = gridCall.RowsCount;
            for (int i = 3; i < rowCount; i++)
            {
                object code = gridCall[i, 0].Value;
                object value = gridCall[i, 2].Value;

                double curVal = Convert.ToDouble(value);

                if (code.ToString() == a_PriceCode && curVal == a_Val)
                {
                    rowID = i;
                    break;
                }
            }

            return rowID;
        }

        private int FindCallBreakDownID(string a_PriceCode, double a_Val)
        {
            int rowID = -1;

            int rowCount = gridCall.RowsCount;
            for (int i = 3; i < rowCount; i++)
            {
                object code = gridCall[i, 5].Value;
                object value = gridCall[i, 7].Value;

                double curVal = Convert.ToDouble(value);

                if (code.ToString() == a_PriceCode && curVal == a_Val)
                {
                    rowID = i;
                    break;
                }
            }

            return rowID;
        }


        private int FindPutBreakUpID(string a_PriceCode, double a_Val)
        {
            int rowID = -1;

            int rowCount = gridPut.RowsCount;
            for (int i = 3; i < rowCount; i++)
            {
                object code = gridPut[i, 0].Value;
                object value = gridPut[i, 2].Value;

                double curVal = Convert.ToDouble(value);

                if (code.ToString() == a_PriceCode && curVal == a_Val)
                {
                    rowID = i;
                    break;
                }
            }

            return rowID;
        }

        private int FindPutBreakDownID(string a_PriceCode, double a_Val)
        {
            int rowID = -1;

            int rowCount = gridPut.RowsCount;
            for (int i = 3; i < rowCount; i++)
            {
                object code = gridPut[i, 5].Value;
                object value = gridPut[i, 7].Value;

                double curVal = Convert.ToDouble(value);

                if (code.ToString() == a_PriceCode && curVal == a_Val)
                {
                    rowID = i;
                    break;
                }
            }

            return rowID;
        }


        #endregion
    }
}
